import os
from flask import jsonify
from ..util import trueReturn, falseReturn


# 统计文件中特定字符串出现的次数
def findStr(file, str_):
    count = 0
    for line in file:
        time = str(line).count(str_)
        count += time
    return count


# 获取角色和用例个数
def getActorandUseCase(file_name):
    # 获取角色个数
    actor_count = findStr(file_name, "<o:Actor Id")
    # 获取用例个数
    use_case_count = findStr(file_name, "<o:UseCase Id")
    print('Actor count: ', actor_count)
    print('Use case count: ', use_case_count)
    # 返回 JSON 格式的成功响应
    json_data = {
        'actor_count': actor_count,
        'use_case_count': use_case_count
    }
    return trueReturn(json_data, 'ok')

# 测试
if __name__ == '__main__':
    file_name = "D:\Downloads\CCMS_UseCase.oom"
    getActorandUseCase(file_name)


